import * as userApi from '@/api/user'
import dayjs from 'dayjs'
Component({
  properties: {
    userInfo: {
      type: Object,
      value: {},
      observer: function(newVal, oldVal) {
        this.setData({
          group: newVal.groupOp
        })
        if(!newVal.testId) {
          userApi.reqCurProgress().then(res => {
            this.setData({
              time: dayjs(res.data[0].begin).format('YYYY-MM-DD'),
              disabled: true,
              title: '已提交报名'
            })
          })
        }else{
          userApi.reqCurProgress().then(res1 => {
            userApi.reqCurTest(newVal.testId).then(res2 => {
              this.setData({
                title: res2.data.name,
                time: dayjs(res2.data.begin).format('YYYY-MM-DD'),
                disabled: res2.data.fileList ? false : true,
              })
              res1.data.forEach((item, index) => {
                if(res2.data.name === item.name) {
                  this.setData({
                    status: index + 1
                  })
                }
              })
            })
          })
        }
      }
    }
  },
  data: {
    status: 0,
    group: '',
    time: '',
    disabled: false,
    title: ''
  },
  methods: {
    gotoDetail() {
      wx.navigateTo({
        url: '/pages/detail/detail',
      })
    }
  }
})